<template>
	<view class="task-wrap">
		<view class="form-aera">
			<view class="buttons">
				<button class="scan-btn" type="primary" @click="scanCodeEvent">
					<image class="icon" src="/static/scan-btn.svg"></image>
					<text style="margin-left: 5px;">扫一扫</text>
				</button>
			</view>
		</view>
		<tabBar></tabBar>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				id: "",
			}
		},
		created() {
			this.scanCodeEvent()
		},
		methods: {

			/** 扫码事件**/
			scanCodeEvent() {
				wx.scanCode({
					onlyFromCamera: false, //值为 false  既可以使用相机也可以使用相册，  值为true 只能使用相机
					scanType: ['barCode', 'qrCode', 'datamatrix',
						'pdf417'
					], //分别对应 一维码  二维码  DataMatrix码  PDF417条码  
					success: async (res) => { //扫码成功后
						console.log(res)
						console.log(res.result) //所扫码的内容
						// console.log(res.scanType) 所扫码的类型
						// console.log(res.charSet) 所扫码的字符集
						// console.log(res.path) 当所扫的码为当前小程序二维码时，会返回此字段，内容为二维码携带的 path
						// console.log(res.rawData) 原始数据，base64编码
						var string = res.result.split("=")[1]; //分割取出cid
						console.log(string)
						this.id = string

						this.$api.sceneDevice({
							id: this.id
						}, res => {
							if (res.code === 200) {
								var datainfo = res.result || {}
								if (datainfo.applyStatus != 3) {
									wx.navigateTo({
										url: '/pages/warehouse/index?id=' + this.id
									})
								} else {
									wx.navigateTo({
										url: '/pages/storage/index?id=' + this.id
									})
								}
							}

						})

					},
					fail: (res) => { //扫码失败后
						wx.showToast({
							title: '扫码失败',
							icon: 'loading',
							duration: 1500
						})
					},
				})
			},

			instrument() {
				console.log("打发点")
				wx.redirectTo({
					url: '/pages/instrument/index'
				})
			}

		}
	}
</script>

<style scoped>
	uni-page-body{
		height: 100%;
	}
	.task-wrap{
		background: #F0F2FA;
		height: 100%;
		width: calc(100%-116rpx);
		display: flex;
		flex-direction: column;
		align-items: center;
		/* justify-content: center; */
		padding-left: 58rpx;
		padding-right: 58rpx;
	}
	.form-aera{
		width: 100%;
		margin-top: 350rpx;
	}
	::v-deep .uni-easyinput__content{
		height: 107rpx;
		background: #FFFFFF;
		box-shadow: inset 0rpx 5rpx 11rpx 2rpx rgba(0,0,0,0.16);
		border-radius: 0rpx 0rpx 0rpx 0rpx;
		opacity: 1;
		border: 2px solid #FFFFFF
	}
	::v-deep .uni-easyinput__placeholder-class {
        font-size: 32rpx;
        font-weight: 400;
        color: #B7B7B7;
    }
	.buttons{
		margin-top: 5px;
		margin-left: 100px;
		width: 100%;
		height: 75rpx;
/* 		display: flex;
		align-items: center;
		justify-content: space-between; */
	}
	.scan-btn{
		height: 100%;
		width: 43%;
		color: #2F3A89;
		font-size: 32rpx;
		background-color: #D3DDF9;
		box-shadow: 5rpx 5rpx 11rpx 2rpx rgba(0,0,0,0.16);
		border-radius: 9rpx;
		border: 1px solid #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		float: left;
	}
	.confirm-btn{
		height: 100%;
		width: 43%;
		color: #fff;
		font-size: 32rpx;
		background-color: #2F3A89;
		box-shadow: 5rpx 5rpx 11rpx 2rpx rgba(0,0,0,0.16);
		border-radius: 9rpx;
		border: 1px solid #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
		float: right;
	}
	::v-deep .uni-forms-item__label{
		display: none!important;
	}
	.icon{
		width: 48rpx;
		height: 48rpx;
	}
</style>